package org.example.reducejoin;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @ClassName TableBean
 * @Author 小坏
 * @Date 2021/7/29、16:56
 * @Version 1.0
 * <p>
 * Writable 序列化
 */
public class TableBean implements Writable {

    /**
     * order表
     * id   pid     amount
     * <p>
     * pd表
     * pid      pname
     */

    private String id; // 订单id
    private String pid; // 产品id
    private int amount; // 产品数量
    private String pname; // 产品名称
    private String flag; // 表的标记

    public TableBean() {
    }


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public String getPname() {
        return pname;
    }

    public void setPname(String pname) {
        this.pname = pname;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    /**
     * 序列化 的顺序必须和反序列化一致
     *
     * @param out
     * @throws IOException
     */
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(id); //string 使用writeUTF
        out.writeUTF(pid); //string 使用writeUTF
        out.writeInt(amount); //string 使用writeUTF
        out.writeUTF(pname); //string 使用writeUTF
        out.writeUTF(flag); //string 使用writeUTF
    }

    /**
     * 反序列化
     *
     * @param in
     * @throws IOException
     */
    @Override
    public void readFields(DataInput in) throws IOException {
        this.id = in.readUTF();
        this.pid = in.readUTF();
        this.amount = in.readInt();
        this.pname = in.readUTF();
        this.flag = in.readUTF();
    }


    @Override
    public String toString() {
        return id + "\t" + pname + "\t" + amount;
    }
}
